package com.lb.statck.controller;

import com.lb.statck.common.result.Result;
import com.lb.statck.pojo.dto.ShopDto;
import com.lb.statck.pojo.vo.ShopCartVO;
import com.lb.statck.service.ShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
 @RestController
@RequestMapping("/api/shopcart")
public class ShopCartController {
    @Autowired
    private ShopCartService shopCartService;

    @PostMapping("/insert")
    public Result insertShop(@RequestBody ShopDto shopDto)
    {
       shopCartService.insert(shopDto);
       Result result = new Result();
       result.setData(shopDto);
       return result;
    }
    @PostMapping("/get")
    public Result getShop(@RequestBody ShopDto shopDto)
    {
        List<ShopCartVO> resul= shopCartService.get();
        if(resul.size()>0){
            Result result = new Result();
            result.setCode(1);
            result.setData(resul);
            return result;
        }else {
        Result result = new Result();
         result.setCode(0);
        return result;
    }}
    @GetMapping("/delete")
    public Result deleteShop(@RequestParam(value = "userId") String userId){
        shopCartService.deleteShop(userId);
        Result result = new Result();
           return result;
    }

    @PostMapping("updatenum")
    public Result updateShop(@RequestBody ShopDto shopDto){

        shopCartService.updateNum(shopDto);
        return null;
    }
}
